package com.pxst.sys.controller;

import com.pxst.annotations.LogOperate;
import com.pxst.resp.ApiResp;
import com.pxst.sys.entity.SysConfig;
import com.pxst.sys.entity.SysConfigDetail;
import com.pxst.sys.req.ConfigDeleteRsp;
import com.pxst.sys.req.ConfigInsertRsp;
import com.pxst.sys.req.ConfigInsertRspSub;
import com.pxst.sys.service.SysConfigDetailService;
import com.pxst.sys.service.SysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Txd
 * @since 2023-09-05 17:01:29
 */
@Validated
@RestController
@RequestMapping("/sys/config")
@Api(tags = "系统配置接口")
public class SysConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    /**
     * 新增系统配置主表
     * @param fConfigRsp
     * @return ApiResp
     */
    @PostMapping("/addConfig")
    @ApiOperation(value = "新增系统配置主表")
    @LogOperate(operate = "新增系统配置主表", service = SysConfigService.class, type = "add")
    public ApiResp addConfig(@RequestBody @Validated ConfigInsertRsp fConfigRsp) {
        return sysConfigService.addConfig(fConfigRsp);
    }

    /**
     * 新增系统配置子表
     * @param configRsp
     * @return ApiResp
     */
    @PostMapping("/addConfigSub")
    @ApiOperation(value = "新增系统配置子表")
    @LogOperate(operate = "新增系统配置子表", service = SysConfigDetailService.class, type = "add")
    public ApiResp addConfigSub(@RequestBody @Validated ConfigInsertRspSub configRsp) {
        return sysConfigService.addConfigSub(configRsp);
    }

    /**
     * 删除系统配置
     * @param configDeleteRsp
     * @return ApiResp
     */
    @DeleteMapping("/deleteConfig")
    @ApiOperation(value = "删除系统配置")
    @LogOperate(operate = "删除系统配置", service = SysConfigService.class, type = "del")
    public ApiResp deleteConfig(ConfigDeleteRsp configDeleteRsp) {
        return sysConfigService.deleteConfig(configDeleteRsp);
    }

    /**
     * 获取所有系统配置主表，前端根据主表code获取子表
     * @return ApiResp
     */
    @GetMapping("/getConfigAll")
    @ApiOperation(value = "获取所有系统配置")
    public ApiResp getConfigAll() {
        return sysConfigService.getConfigAll();
    }

    /**
     * 根据code获取系统配置
     * @param code
     * @return ApiResp
     */
    @GetMapping("/getConfigByCode/{code}")
    @ApiOperation(value = "根据主配置表code获取系统配置")
    public ApiResp getConfigByCode(@PathVariable @ApiParam("主配置表编码")String code) {
        return sysConfigService.getConfigByCode(code);
    }

    /**
     * 修改系统配置主表
     * @param sysConfig
     * @return ApiResp
     */
    @PutMapping("/updateConfig")
    @ApiOperation(value = "修改系统配置主表")
    @LogOperate(operate = "修改系统配置主表", service = SysConfigService.class, type = "edit")
    public ApiResp updateConfigById(@RequestBody SysConfig sysConfig) {
        return sysConfigService.updateConfig(sysConfig);
    }

    /**
     * 修改系统配置子表
     * @param sysConfigDetail
     * @return ApiResp
     */
    @PutMapping("/updateConfigSub")
    @ApiOperation(value = "修改系统配置子表")
    @LogOperate(operate = "修改系统配置子表", service = SysConfigDetailService.class, type = "edit")
    public ApiResp updateConfigSubById(@RequestBody SysConfigDetail sysConfigDetail) {
        return sysConfigService.updateConfigSub(sysConfigDetail);
    }


}
